<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加考勤时间</title>
<link rel="icon" href="<c:url value='/imgs/logo.ico' />" />
<link type="text/css" rel="stylesheet" href="<c:url value='/css/index.css' />" />
<link type="text/css" rel="stylesheet" href="<c:url value='/css/add.css' />" />
<script type="text/javascript" charset="utf-8" src="<c:url value='/scripts/jquery-2.1.0.js'/>"></script>
</head>
<body>
	<div class="container">
		<%@ include file="/jsps/top.jsp"%>
		<div class="main">
			<form class="form mechanism">
				<h2>添加考勤时间</h2>
				<table>
					<tr>
						<td><label>机&nbsp;构&nbsp;号：</label></td>
						<td>
							<input type="text" class="txt" name="mechid" value="${daytime.mechanism.mechid }" placeholder="请输入4位数字" maxlength="4" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error0"></span>
						</td>
					</tr>
					<tr>
						<td><label>开始日期：</label></td>
						<td>
							<input type="text" class="txt" name="daybdate" value="${daytime.daybdate" }"  placeholder="请输入如2017-11-15的格式" maxlength="10" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error1"></span>
						</td>
					</tr>
					<tr>
						<td><label>结束日期：</label></td>
						<td>
							<input type="text" class="txt" name="dayedate" value="${daytime.dayedate }"  placeholder="请输入如2018-11-15的格式" maxlength="10" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error2"></span>
						</td>
					</tr>
					<tr>
						<td><label>上班时间：</label></td>
						<td>
							<input type="text" class="txt" name="begintime" value="${daytime.begintime }"  placeholder="请输入如08:00的格式" maxlength="8" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error3"></span>
						</td>
					</tr>
					<tr>
						<td><label>下班时间：</label></td>
						<td>
							<input type="text" class="txt" name="endtime" value="${mechanism.endtime }"  placeholder="请输入如16:30的格式" maxlength="8" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error4"></span>
						</td>
					</tr>
					
				</table>
				<input class="btn addBtn" type="button" value="添加"/>
				<input class="btn" type="reset" value="重置"/>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		$(function(){
			$(".top .title").click(function(){
				location.href="<c:url value='/index.jsp'/>";
			});	
			
			$(".main .form .addBtn").click(function(){
				$(".main .form .error").text("");
				var mechid = $("input[name='mechid']").val();
				var daybdate = $("input[name='daybdate']").val();
				var dayedate = $("input[name='dayedate']").val();
				var begintime = $("input[name='begintime']").val();
				var endtime = $("input[name='endtime']").val();
				if($.isEmptyObject(mechid.trim())||$.isEmptyObject(mechname.trim())||$.isEmptyObject(mechip.trim())||$.isEmptyObject(minsimilarity.trim())){
					alert("输入内容不能为空！");
				}else{
					$.ajax({
						type : "post",
						url : "<c:url value='/addMechanism'/>",
						data : {"type":"add","mechid":mechid,"mechname":mechname,"mechip":mechip,"minsimilarity":minsimilarity},
						dataType: "json",
						success : function(data) {
							if(data.flag=="1"){
								if($.isEmptyObject(data.mechid)){
									data.mechid = "";
								}
								if($.isEmptyObject(data.mechname)){
									data.mechname = "";
								}
								if($.isEmptyObject(data.mechip)){
									data.mechip = "";
								}
								if($.isEmptyObject(data.minsimilarity)){
									data.minsimilarity = "";
								}
								$(".main .form .error0").text(data.mechid);
								$(".main .form .error1").text(data.mechname);
								$(".main .form .error2").text(data.mechip);
								$(".main .form .error3").text(data.minsimilarity);
							}else{
								alert("添加成功!");
							}
						},
						error : function() {
							alert("操作失败，请重试！");
						}
					});
				}
			});
		})
	</script>
</body>
</html>

